﻿using AutoMapper;
using MediatR;
using T_settlement.API.Application.Command.InvoiceCommand;
using T_settlement.Domain;
using T_settlement.Infrastructure.Impl;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.InvoiceCommandHandlers
{
    public class UpdateInvoiceCommandHandlers:IRequestHandler<UpdateInvoiceCommand,int>
    {
        private readonly InvoiceRepository _invoiceRepository;
        private readonly IMapper mapper;

        public UpdateInvoiceCommandHandlers(InvoiceRepository invoiceRepository, IMapper mapper)
        {
            _invoiceRepository = invoiceRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(UpdateInvoiceCommand request, CancellationToken cancellationToken)
        {

            var info = mapper.Map<Invoice>(request);
            info.UpdateBy = "李四";
            info.UpdateDate = DateTime.Now;
            info.CreateBy = "张三";
            info.InvoiceNumber = "SY" + DateTime.Now.ToString("yyyyMMddss");
            return await _invoiceRepository.UpdateAsync(info);
            //var info = new Invoice();
            //info.Ticket = request.Ticket;
            //info.InvoiceNumber = request.InvoiceNumber;
            //info.InvoiceType = request.InvoiceType;
            //info.InvoiceAmount = request.InvoiceAmount;
            //info.Rate = request.Rate;
            //info.Tax = request.Tax;
            //info.Invoicetime = request.Invoicetime;
            //info.Remark = request.Remark;
            //info.UpdateBy = "李四";
            //info.UpdateDate = DateTime.Now;
            //info.InvoiceId= request.InvoiceId;
            //info.CreateBy = "张三";
            //info.InvoiceNumber = "SY" + DateTime.Now.ToString("yyyyMMddss");
            //return await _invoiceRepository.UpdateAsync(info);
        }
    }
}
